package com.red.wine.adapter;

import java.util.List;

import com.red.wine.R;
//import com.red.wine.adapter.TasteAdapter.Composites;
import com.red.wine.model.CityListInfo;
import com.red.wine.model.TasteInfo;
import com.red.wine.util.StringUtil;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CityAdapter extends BaseAdapter{
	private Context context;
	private List<CityListInfo> datasource;
	public CityAdapter(Context context, List<CityListInfo> datasource) {
		this.context = context;
		this.datasource = datasource;
	}
	public int getCount() {
		if(datasource != null && datasource.size() > 0){
			return datasource.size();
		}else{
			return 0;
		}
		
	}

	public void refresh(List<CityListInfo> datasource) {
		this.datasource = datasource;
		notifyDataSetChanged();
	}
	
	public Object getItem(int position) {
		return datasource.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		Holder composites= null;  
		if(convertView == null ) {
           composites = new Holder();
           convertView = LayoutInflater.from(context).inflate(R.layout.city_item,null);
           composites.name = (TextView) convertView.findViewById(R.id.city_item_city_name);
           convertView.setTag(composites);
//           CityListInfo taskInfo = datasource.get(position);
       }else {//在convertView不为空时，Recycler根据旧的item根据数据进行置换，从而直接使用旧的item即可！
    	   composites =  (Holder) convertView.getTag();
       }
		
       //加载数据
		if(!StringUtil.isEmptyOrNull(datasource.get(position).getName().toString())){
			composites.name.setText(datasource.get(position).getName().toString() + "");
		}
		 
       return convertView;
	}

	public class Holder {
		public TextView name;
	}
}
